package xyz.yuzegod.megawalls.classes.mythic.werewolf;

import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;

import java.util.ArrayList;
import java.util.List;

public class SecondSkill extends Skill
{
    public SecondSkill(final Classes classes) {
        super("嗜血", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 4.0;
            }
            case 2: {
                return 6.0;
            }
            case 3: {
                return 8.0;
            }
            default: {
                return 4.0;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7连续3次近战攻击或箭矢命中,");
            lore.add("   §7而自身未受到伤害时,将获得持续");
            lore.add("   §a" + this.getAttribute(level) + "§7秒的速度I和抗性提升II效果。");
            return lore;
        }
        lore.add(" §8▪ §7连续3次近战攻击或箭矢命中,");
        lore.add("   §7而自身未受到伤害时,将获得持续");
        lore.add("   §8" + this.getAttribute(level - 1) + " ➜");
        lore.add("   §a" + this.getAttribute(level) + "§7秒的速度I和抗性提升II效果。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill2Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill2Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        Werewolf.skill2.put(gamePlayer, Werewolf.skill2.getOrDefault(gamePlayer, 0) + 1);
        if (Werewolf.skill2.get(gamePlayer) >= 3) {
            gamePlayer.sendMessage("§e你的嗜血技能让你获得" + this.getAttribute(this.getPlayerLevel(gamePlayer)) + "秒的速度I和抗性提升II效果。");
            final Player player = gamePlayer.getPlayer();
            if (player.hasPotionEffect(PotionEffectType.SPEED)) {
                player.removePotionEffect(PotionEffectType.SPEED);
            }
            player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, (int)this.getAttribute(this.getPlayerLevel(gamePlayer)) * 20, 0));
            if (player.hasPotionEffect(PotionEffectType.DAMAGE_RESISTANCE)) {
                player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
            }
            player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, (int)this.getAttribute(this.getPlayerLevel(gamePlayer)) * 20, 1));
            Werewolf.skill2.put(gamePlayer, 0);
        }
        return true;
    }
    
    @Override
    public String getSkillTip(final GamePlayer gamePlayer) {
        final int damage = Werewolf.skill2.getOrDefault(gamePlayer, 0);
        if (damage == 0) {
            return null;
        }
        return this.getClasses().getNameColor() + "§l" + this.getName() + " " + damage;
    }
}
